<?php

require_once 'vendor/autoload.php';
$app = require_once 'bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

$request = new Illuminate\Http\Request();
$controller = new App\Http\Controllers\Api\DepartmentController();
$result = $controller->tree($request);
$data = $result->getData();

if ($data->success) {
    echo '✅ 树形结构API工作正常' . PHP_EOL;
    echo '根部门数量: ' . count($data->data) . PHP_EOL;
    foreach ($data->data as $dept) {
        $childCount = isset($dept->children) ? count($dept->children) : 0;
        echo "- {$dept->name}: {$childCount} 个子部门" . PHP_EOL;
    }
} else {
    echo '❌ API错误: ' . $data->message . PHP_EOL;
}